package com.panasonic.web.controller.exam;


import com.panasonic.web.domain.cms.CmsExamQuestion;
import com.panasonic.web.service.ICmsExamQuestionService;
import com.panasonic.web.vo.CmsExamQuestionNotAnswerVo;
import com.panasonic.common.annotation.Log;
import com.panasonic.common.core.controller.BaseController;
import com.panasonic.common.core.domain.AjaxResult;
import com.panasonic.common.core.page.TableDataInfo;
import com.panasonic.common.enums.BusinessType;
import com.panasonic.common.utils.bean.ListBeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 试卷问题Controller
 * 
 * @author lwf
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/cms/question")
@Api(value = "CmsExamQuestion", tags = "试卷问题")
public class CmsExamQuestionController extends BaseController
{
    @Autowired
    private ICmsExamQuestionService cmsExamQuestionService;

    /**
     * 查询试卷问题列表
     */
    @ApiOperation(value = "查询")
    @GetMapping("/list")
    public TableDataInfo list(CmsExamQuestion cmsExamQuestion)
    {
        startPage();
        List<CmsExamQuestion> list = cmsExamQuestionService.selectCmsExamQuestionList(cmsExamQuestion);
        List<CmsExamQuestionNotAnswerVo> cmsExamQuestionNotAnswerVos = ListBeanUtil.copyListProperties(list, CmsExamQuestionNotAnswerVo::new);
        TableDataInfo dataTable = getDataTable(cmsExamQuestionNotAnswerVos);
        dataTable.setRows(cmsExamQuestionNotAnswerVos);
        return dataTable;
    }



    /**
     * 获取试卷问题详细信息
     */
    @ApiOperation(value = "获取试卷问题详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsExamQuestionService.selectCmsExamQuestionById(id));
    }

    /**
     * 新增试卷问题
     */
    @ApiOperation(value = "新增试卷问题")
    @Log(title = "试卷问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsExamQuestion cmsExamQuestion)
    {
        return toAjax(cmsExamQuestionService.insertCmsExamQuestion(cmsExamQuestion));
    }

    /**
     * 修改试卷问题
     */
    @ApiOperation(value = "修改试卷问题")
    @Log(title = "试卷问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsExamQuestion cmsExamQuestion)
    {
        return toAjax(cmsExamQuestionService.updateCmsExamQuestion(cmsExamQuestion));
    }

    /**
     * 删除试卷问题
     */
    @ApiOperation(value = "删除试卷问题")
    @Log(title = "试卷问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsExamQuestionService.deleteCmsExamQuestionByIds(ids));
    }


}
